package com.dongdongshop.aopconfig;


import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AopConfig {
    private Logger logger = LoggerFactory.getLogger(AopConfig.class);

    @Pointcut("execution(public * com.dongdongshop.service.*.*(..))")
    public void aopLog(){}

    //定义前置通知
    @Before("aopLog()")
    public void doBefore(JoinPoint joinPoint){
        //参数获取
        Object[] args = joinPoint.getArgs();
        //获取调用方法
        Signature signature = joinPoint.getSignature();
        logger.info("正在进入 {} 方法,参数为: {} ",signature,args);
    }

    //定义返回后通知
    @AfterReturning(pointcut = "aopLog()",returning = "result")
    public void  doAfter(Object result)throws Throwable{
        //打印返回结果
        logger.info("执行成功,结果为{}", JSONObject.toJSONString(result));
    }

}






















